package cn.zime.iot.entity;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class UserDao {

    /***
     * 用户注册
     */
    public int addUser(Connection con,User user)throws Exception {
    	String sql="insert into manager values(null,?,?)";
    	PreparedStatement pst=con.prepareStatement(sql);
    	 pst.setString(1,user.getName());
         pst.setString(2,user.getPassword());
         return pst.executeUpdate();
    }
    public int changePassWord(Connection con,User user)throws Exception{
        String sql="update manager set pwd=? where user_name =? and pwd=?";
        PreparedStatement pst=con.prepareStatement(sql);
        pst.setString(1,user.getPassword());
        pst.setString(2,user.getName());
        pst.setString(3,user.getOld_password());
        return pst.executeUpdate();
    }
    public int findPassWord(Connection con,User user)throws Exception{
        String sql="update manager set pwd=? where user_name =?";
        PreparedStatement pst=con.prepareStatement(sql);
        pst.setString(1,user.getPassword());
        pst.setString(2,user.getName());
        return pst.executeUpdate();
    }
    public int delete(Connection con,User user)throws Exception{
        String sql="delete from manager where user_name =?";
        PreparedStatement pst=con.prepareStatement(sql);
        pst.setString(1,user.getName());
        return pst.executeUpdate();
    }
}
